Locksmith by Emily Short begins here. "Implicit handling of doors and containers so that lock manipulation is automatic if the player has the necessary keys." Volume 1 - Automatic locking and unlocking with necessary actions Use sequential action translates as (- Constant SEQUENTIAL_ACTION; -). Before going through a closed door (called the blocking door): if using the sequential action option begin; try opening the blocking door; otherwise; say "(first opening [the blocking door])[line break]"; silently try opening the blocking door; end if; if the blocking door is closed, stop the action. Before locking an open thing (called the door ajar) with something: if using the sequential action option begin; try closing the door ajar; otherwise; say "(first closing [the door ajar])[line break]"; silently try closing the door ajar; end if; if the door ajar is open, stop the action. Before locking keylessly an open thing (called the door ajar): if using the sequential action option begin; try closing the door ajar; otherwise; say "(first closing [the door ajar])[line break]"; silently try closing the door ajar; end if; if the door ajar is open, stop the action. Before opening a locked thing (called the sealed chest): if using the sequential action option begin; try unlocking keylessly the sealed chest; otherwise; say "(first unlocking [the sealed chest])[line break]"; silently try unlocking keylessly the sealed chest; end if; if the sealed chest is locked, stop the action. Before someone trying going through a closed door (called the blocking door) (this is the intelligently opening doors rule): try the person asked trying opening the blocking door; if the blocking door is closed, stop the action. Before someone trying locking an open thing (called the door ajar) with something (this is the intelligently closing doors rule): try the person asked trying closing the door ajar; if the door ajar is open, stop the action. Before someone trying locking keylessly an open thing (called the door ajar) (this is the intelligently closing keyless doors rule): try the person asked trying closing the door ajar; if the door ajar is open, stop the action. Before someone trying opening a locked thing (called the sealed chest) (this is the intelligently opening containers rule): try the person asked trying unlocking keylessly the sealed chest; if the sealed chest is locked, stop the action. Volume 2 - Default locking and unlocking Part 1 - The matching key rule This is the need a matching key rule: if the noun has a matching key begin; let the item be the matching key of the noun; if the person asked encloses the item and the person asked does not carry the item, silently try the person asked trying taking the item; if the person asked has the item, continue the action; if the item is a passkey begin; if the item unbolts the noun and the item can be touched by the person asked begin; if the person asked is the player begin; if using the sequential action option begin; try taking the item; otherwise; say "(first taking [the item])[line break]"; try silently taking the item; end if; otherwise; try the person asked trying taking the item; end if; end if; end if; if the person asked has the item, continue the action; end if; if the person asked is the player, say "You lack a key that fits [the noun]."; stop the action. Part 2 - Unlocking keylessly Understand "unlock [something]" as unlocking keylessly. Unlocking keylessly is an action applying to one thing. Check unlocking keylessly: abide by the can't unlock without a lock rule; abide by the can't unlock what's already unlocked rule; abide by the need a matching key rule. Carry out unlocking keylessly: if using the sequential action option, do nothing; otherwise say "(with [the matching key of the noun])[line break]"; try unlocking the noun with the matching key of the noun. Check someone trying unlocking keylessly: abide by the can't unlock without a lock rule; abide by the can't unlock what's already unlocked rule; abide by the need a matching key rule. Carry out someone trying unlocking keylessly: try the person asked trying unlocking the noun with the matching key of the noun. Part 3 - Locking keylessly Understand "lock [something]" as locking keylessly. Locking keylessly is an action applying to one thing. Check locking keylessly: abide by the can't lock without a lock rule; abide by the can't lock what's already locked rule; abide by the can't lock what's open rule; abide by the need a matching key rule. Carry out locking keylessly: if using the sequential action option, do nothing; otherwise say "(with [the matching key of the noun])[line break]"; try locking the noun with the matching key of the noun. Check someone trying locking keylessly: abide by the can't lock without a lock rule; abide by the can't lock what's already locked rule; abide by the can't lock what's open rule; abide by the need a matching key rule. Carry out someone trying locking keylessly: try the person asked trying locking the noun with the matching key of the noun. Volume 3 - The Passkey kind, needed only if you want keys to name themselves A passkey is a kind of thing. The specification of a passkey is "A kind of key whose inventory listing changes to reflect the player's knowledge about what it unlocks." Definition: a passkey is identified if it unbolts something. Unbolting relates one passkey to various things. The verb to unbolt (it unbolts, they unbolt, it unbolted, it is unbolted) implies the unbolting relation. After printing the name of an identified passkey (called the item) while taking inventory: say " (which opens [the list of things unbolted by the item])"; After examining an identified passkey (this is the passkey description rule): say "[The noun] unlocks [the list of things unbolted by the noun]." Carry out unlocking something with a passkey: if the second noun is the matching key of the noun, now the second noun unbolts the noun. Report someone trying unlocking something with a passkey: now the second noun unbolts the noun. Volume 4 - Unlocking all - Not for release Understand "unlockall" as universal unlocking. Universal unlocking is an action applying to nothing. Carry out universal unlocking: repeat with item running through locked things begin; now the item is unlocked; say "Unlocking [the item]."; end repeat. Report universal unlocking: say "A loud stereophonic click assures you that everything in the game has been unlocked." Locksmith ends here. ---- DOCUMENTATION ---- Locksmith adds implicit handling of doors and containers so that lock manipulation is automatic if the player has the necessary keys. There are four parts of Locksmith. First, Locksmith will try opening all doors the player tries to pass through; try closing all lockables before locking them; and try unlocking all locked items before opening them. Other characters will follow the same rules. By default, these actions are described as other automatic actions usually are in Inform: the player sees something like "(first unlocking...)" before he opens the door. The "Use sequential action" mode is provided for the case where we would prefer to see "You unlock the door." instead. Second, Locksmith tries to provide an intelligent default if no key is specified, so that >LOCK DOOR will work if the player is holding the correct key. Third, Locksmith introduces a kind called the passkey. The passkey is a key which will name itself in inventory listings after use. Once the passkey has been identified, the game also automates taking the key before using it on the door it matches. Keys the player has never successfully identified, or keys not defined as belonging to the passkey kind, will not behave this way. Passkeys are also renamed if the player has seen another character use them successfully. The "unbolts" relation is used to keep track of what the player knows about keys. We will probably not need to do this in most cases, but it is possible to change this manually during play to give the player new knowledge (or ignorance) about the functions of keys. Finally, Locksmith provides the debugging command 'unlockall', only identified in debugging compilations of the game. If during play we type UNLOCKALL, all locks in the game will magically spring open. Example: * Latches - Adding one lock in the game that is managed by latch rather than by a key. Suppose that most of the doors in our game are locked with normal keys, but one is the kind that simply latches. We can handle this with a specific before rule that fires prior to the more general before rules in Locksmith. We also want to treat LOCK X differently from LOCK X WITH..., so we will treat locking and locking keylessly with separate rules. Locking keylessly is the action invoked if the player types only LOCK X. "John Malkovich's Toilet" Include Locksmith by Emily Short. The Bathroom is a room. The bathroom door is a door. It is north of the Bathroom and south of the Bedroom. It is lockable and locked. Before unlocking keylessly the bathroom door: if the bathroom door is unlocked, say "[The bathroom door] is already unlocked." instead; try turning the latch instead. Before locking keylessly the bathroom door: if the bathroom door is locked, say "[The bathroom door] is already secure." instead; try turning the latch instead. Before locking the bathroom door with something: say "The bathroom door locks with a latch, not with a key." instead. Before unlocking the bathroom door with something: say "The bathroom door locks with a latch, not with a key." instead. The latch is part of the bathroom door. "A turnable tab that locks the door." Understand "knob" as the latch. The description of the bathroom door is "Uninteresting save for the latch." Instead of turning the latch: if the bathroom door is locked begin; say "Click! You turn the latch, and the door is unlocked[if the door is open] and open[end if]."; change bathroom door to unlocked; otherwise; say "Click! You turn the latch, and the door is locked[if the door is open], but open; the lock will catch as soon as you shut the door[end if]."; change bathroom door to locked; end if. The little black oval door is a door. It is west of the Bathroom and east of Oblivion. It is lockable and locked. The description of the oval door is "It is in the wall of the shower area, and opens who knows where. You are sure it was not there yesterday." The onyx key unlocks the oval door. It is in the Bedroom. "On the floor, jagged black in the square of sunlight, is [an onyx key]." Test me with "x bathroom door / unlock oval door / unlock bathroom door / g / go through bathroom door / get key / lock bathroom door / close bathroom door / s / lock bathroom door with onyx key / w". Example: ** Tobacco - Passkeys that open more than one thing each. Here we explore having keys each of which unlocks several items: "Tobacco" Include Locksmith by Emily Short. The Hollow Tree is a room. Below the Hollow Tree is the Vast Hall. Northwest of the Vast Hall is a copper door. The copper door is a locked lockable door. Northwest of the copper door is the Copper Chamber. The Copper Chamber contains a chest and a small dog. The chest contains a large quantity of copper pence. The chest is lockable, closed, openable, and locked. The description of the small dog is "Its eyes are as big as teacups." The small dog is an animal. The copper key unlocks the copper door. It unlocks the chest. The copper key is a passkey. The description of the copper key is "On the head of the key is engraved a precisely delineated teapot." North of the Vast Hall is a silver door. The silver door is a locked lockable door. North of the silver door is the Silver Chamber. The Silver Chamber contains a sarcophagus and a medium dog. The sarcophagus contains a large quantity of silver pence. The sarcophagus is lockable, closed, openable, and locked. The description of the medium dog is "Its eyes are as big as millwheels." The medium dog is an animal. The silver key unlocks the silver door. It unlocks the sarcophagus. The silver key is a passkey. The description of the silver key is "On the head of the key is engraved a very small but detailed watermill." Northeast of the Vast Hall is a gold door. The gold door is a locked lockable door. North of the gold door is the Gold Chamber. The Gold Chamber contains a wardrobe and a large dog. The wardrobe contains a large quantity of gold coins. The wardrobe is lockable, closed, openable, and locked. The description of the large dog is "Its eyes are as big as towers, and turn round and round in its head like wheels." The large dog is an animal. The gold key unlocks the gold door. It unlocks the wardrobe. The gold key is a passkey. The description of the gold key is "On the head of the key is engraved a very small but detailed tower." The tinderbox is in the Vast Hall. The tinderbox contains the silver key, the gold key, and the copper key. The tinderbox is openable and closed. The player carries some chewing tobacco. Test me with "d / n / i / get tinderbox / open tinderbox / i / nw / drop key / lock door / drop key / unlock chest / get copper key / unlock chest / enter door / n / i / x silver / x copper / unlock sarcophagus / x silver". Example: ** Rekeying - Modifying the way passkey descriptions work. As a default, Locksmith describes what passkeys unlock only after printing their default description. Under some circumstances, however, we might want to override that behavior, like this: "Rekeying" Include Locksmith by Emily Short. The player carries a passkey called the tin key. The tin key unlocks the tin box. The tin box is closed, openable, lockable, and locked. In the box is a single Cheerio. Cereality is a room. "The newly-opened 'cereal bar' allows you to mix and match cereal types at will." The box is in Cereality. A procedural rule: ignore the passkey description rule. The description of a passkey is usually "[if the item described unbolts something][The item described] unlocks [the list of things unbolted by the item described][otherwise]You have yet to discover what [the item described] unlocks[end if]." Test me with "i / x key / unlock box / i / x key". Example: *** Watchtower - Using sequential actions to make the player's activities more equal with those of another character. Suppose that instead of the "(first unlocking...)" text, we would like to offer some more interesting flavor text. We might accomplish this by using the sequential action option and then supplying new report rules for specific actions. (Notice that we do not make them After... rules, on the grounds that those would stop the action process. We want to report these actions and allow them to succeed normally.) "Watchtower" Use sequential action. Include Locksmith by Emily Short. Bridge is a room. "Beneath this long, narrow bridge is a gully full of ice-water from the mountains above. It runs milky at this time of year, and is not fit to drink. The air off it is bitterly cold. Just north of here is the Roman watchtower, built square and still defensible despite several centuries of neglect." North of Bridge is the tower door. The tower door is a lockable locked door. It is scenery. Understand "watchtower" as the tower door. The tower door is south of the Watchtower. The large iron key unlocks the tower door. The player carries the large iron key. The description of the Watchtower is "The wooden floor has mostly rotted away, exposing the square pit in which the paymaster used to keep the soldiers' coin. It is possible to move around the perimeter of the room without falling in, however." Report unlocking something with something when the player is in Bridge: say "Shivering and fumbling, you manage to unlock [the noun] with [the second noun]. Your fingers are very nearly numb." instead. Report unlocking something with something when the player is in Bridge: say "Shivering and fumbling, you manage to unlock [the noun] with [the second noun]. Your fingers are very nearly numb." instead. Report opening the tower door: say "The tower door resists your first shove or two, but then falls open." instead. Leif is a man in the Bridge. A persuasion rule: persuasion succeeds. Report someone trying unlocking a door with something: say "[The person asked] rattles the handle of [the noun] a few times, then thinks to try [the second noun] on it. 'Bit stiff, this.'" instead. Report someone trying opening the tower door: say "[The person asked] gives [the tower door] several [if the person asked is in the Bridge]shoves[otherwise]firm tugs[end if] before managing to open it." instead. Test me with "drop key / open door / get key / n / s / lock door / drop key / Leif, get key / Leif, n". Leif will also follow the rules about unlocking and opening doors, and have a few special reports of his own -- though in fact we could also arrange matters so that he is unable to do so, by including the following: A procedural rule: ignore the intelligently opening doors rule; ignore intelligently closing doors rule; ignore intelligently closing keyless doors rule; ignore intelligently opening containers rule. ...and now he will be too dim to handle the keys himself.